window.addEventListener("load", function () {
    // 数据传递
    //设置cookie
    var setCookie = function (name, value, day) {
        //当设置的时间等于0时，不设置expires属性，cookie在浏览器关闭后删除
        var expires = day * 24 * 60 * 60 * 1000;
        var exp = new Date();
        exp.setTime(exp.getTime() + expires);
        document.cookie = name + "=" + value + ";expires=" + exp.toUTCString();
    };

    //传递cookie
    var registered = document.querySelector("#enroll");

    var display = document.querySelector('.display');
    var password_text = document.querySelector("#password_text");
    var Confirm_text = document.querySelector("#Confirm_text");
    var Sms_icon = this.document.querySelector("#Sms_icon")
    var Sms_text = this.document.querySelector("#Sms_text")
    var agree = document.querySelector("#agree");


    var flag = -1;
    agree.addEventListener("click", function () {
        flag *= -1;
    })

    registered.addEventListener("click", function () {
        var name = document.getElementById("landing");
        var pass = document.getElementById("Confirm");
        setCookie('userName', name.value, 7)
        setCookie('password', pass.value, 7);


        if (flag == -1) {
            alert(" 请勾选同意协议并注册 《知晓用户协议》");
        }
        else {
            if (Sms_text.getAttribute('index') != "success") {
                Sms_icon.className = "error_icon";
                Sms_text.className = "error";
                Sms_text.innerHTML = "验证码已过期或错误，请重新获取验证码";
            }
            else {
                if (display.className == "success" && password_text.className == "success" && Confirm_text.className == "success") {
                    window.location.href = 'login.html';
                    return false;
                }
                else {
                    alert("存在格式错误");
                }
            }
        }
    })

})